#include "display.h"
#include <fstream>
#include <sstream>
#include <cmath>

void readingfile(int BW, char* datname) {
	const float PI = atan(1.)*4;
	float theta, phi;
	int k,j,r,itemp;
	int cnt = 0;
	char temp;
	string buffer;
	string fn;
	float3 tempv;

	ifstream in(datname);
	ofstream out("points.obj");

	while(getline(in,buffer)) {
		istringstream iss(buffer);
		iss >> temp;
		if (temp == '#') {
			iss >> r;
			cnt = 0;
			continue;
		} else if(temp == '1') {
			k = floor(cnt/2/BW);
			j = (cnt)%(2*BW);
			phi = (PI*k/BW);
//			cout << "k: " << k << " j: " << j << endl;
			theta = (PI*(2*j+1)/4/BW);
			tempv.x = sin(theta)*cos(phi);
			tempv.y = cos(theta);
			tempv.z = sin(theta)*sin(phi);
			tempv = tempv*r;
			out << "v " << tempv.x << " " << tempv.y << " " << tempv.z << endl;
		}
			cnt++;
	}
	in.close();
	out.close();
}
